package edu.guigu.networkconnection.repolist;

import java.util.List;

import edu.guigu.networkconnection.model.RepoResult;
import edu.guigu.networkconnection.network.GithubClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @Description: (用一句话描述)
 * @author yuanc
 * @date 2025/8/26 11:17
 */
public class PeopPresenter {
    private IRepoView iRepoView;
    private GithubClient githubClient;

    public PeopPresenter(IRepoView iRepoView){
        this.iRepoView = iRepoView;
        githubClient = new GithubClient();
    }

    /** 查询远程仓库数据(来源：网络)*/
    public void queryRemoteRepo(){
        // TODO: 视图开始显示 loading
        iRepoView.startLoading();

        // TODO: 进行数据获取
        Call<RepoResult> repoResult =
                githubClient.getGithubApi().searchRepos("arkts",1,10);
        repoResult.enqueue(new Callback<RepoResult>() {
            @Override
            public void onResponse(Call<RepoResult> call, Response<RepoResult> response) {
                if(response.isSuccessful()){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    // TODO: 视图开始去适配显示数据
                    iRepoView.showListData(response.body());
                }
                iRepoView.endLoading();
            }

            @Override
            public void onFailure(Call<RepoResult> call, Throwable t) {
                // TODO:
                iRepoView.showErro(t);
            }
        });
    }
}
